<template>
    <div>
        <el-form :model="ruleForm" ref="ruleForm" class="demo-ruleForm">
            <el-form-item label="活动时间" required>
                <el-col :span="7">
                <el-form-item prop="date1">
                    <el-date-picker
                    v-model="ruleForm.date"
                    type="datetime"
                    placeholder="选择开始时间" style="width:310px">
                    </el-date-picker>
                </el-form-item>
                </el-col>
                <el-col :span="4"><p>(结束时间为开始时间+24小时)</p></el-col>
            </el-form-item>
                <el-form-item label="选择将要上架商品的分类">
                    <el-select v-model="ruleForm.category" placeholder="选择商品的分类">
                        <el-option label="电脑" value="computer"></el-option>
                        <el-option label="手机" value="phone"></el-option>
                        <el-option label="平板" value="table_computer"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="输入将要上架商品的ID">
                    <el-input v-model="ruleForm.id" autocomplete="off" style="width:240px" placeholder="输入商品的ID"></el-input>
                </el-form-item>
                <el-form-item label="输入将要上架商品的价格">
                    <el-input v-model="ruleForm.price" autocomplete="off" style="width:240px" placeholder="输入商品的价格"></el-input>
                </el-form-item>
                <el-form-item label="输入将要上架商品的数量">
                    <el-input v-model="ruleForm.nums" autocomplete="off" style="width:240px" placeholder="输入商品的数量"></el-input>
                </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')">立即提交</el-button>
                <el-button @click="resetForm('ruleForm')">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
export default {
    name:"seckill",
    data() {
      return {
        ruleForm: {
          category: '',
          id: '',
          date: '',
          price: '',
          nums: ''
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.ruleForm.date = this.$moment(this.ruleForm.date).format("YYYY-MM-DD HH:mm:ss");
            this.$axios.post("/api/insertSeckill",this.$querystring.stringify({
            shopname:this.$cookies.get("shopname"),
            product_id:this.ruleForm.id,
            category:this.ruleForm.category,
            price:this.ruleForm.price,
            product_nums:this.ruleForm.nums,
            start:this.ruleForm.date
            })).then(reponse=>{
            console.log(reponse);
            if(reponse.data == true){
               alert("提交成功")
            }else{
                alert("提交失败")
            }
            })
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
}
</script>